/*
 * Copyright (C) 2023 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.templateproject.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

import com.bumptech.glide.Glide;
import com.xuexiang.templateproject.MyApp;
import com.xuexiang.templateproject.R;
import com.xuexiang.templateproject.bean.Box;
import com.xuexiang.templateproject.bean.ImageBoxEntity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import kotlin.Metadata;
import kotlin.Unit;
//import kotlin.collections.CollectionsKt__IterablesKt;
//import kotlin.collections.CollectionsKt___CollectionsKt;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.TypeIntrinsics;
//import org.jetbrains.anko.CustomViewPropertiesKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class ImageBoxView extends FrameLayout {

    /* renamed from: a  reason: collision with root package name */
    public int f4412a;

    /* renamed from: b  reason: collision with root package name */
    public ArrayList<Box> mAllBoxList;

    /* renamed from: c  reason: collision with root package name */
    public List<BoxView> mAllBoxViews;

    /* renamed from: d  reason: collision with root package name */
    public ArrayList<Box> mBoxList;

    /* renamed from: e  reason: collision with root package name */
    public List<BoxView> mBoxViews;
    @Nullable

    /* renamed from: f  reason: collision with root package name */
    public ObservableListener mObservableListener;

    /* renamed from: g  reason: collision with root package name */
    public int f4418g;

    /* renamed from: h  reason: collision with root package name */
    public int f4419h;

    /* renamed from: i  reason: collision with root package name */
    public int mBoxCount;

    /* renamed from: j  reason: collision with root package name */
    public int aTempHeight;
    @Nullable

    /* renamed from: k  reason: collision with root package name */
    public OnBoxEditClickListener onBoxEditClickListener;
    @NotNull

    /* renamed from: l  reason: collision with root package name */
    public Map<Integer, View> f4423l = new LinkedHashMap();

    public interface ObservableListener {
        void a(int i2);

        void b(int i2, int i3);
    }

    public interface OnBoxEditClickListener {
        void onEditClick(@NotNull ImageBoxEntity imageBoxEntity, @NotNull BoxView boxView);
    }

    public final class c implements BoxView.OnViewClickListener {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ BoxView boxView;

        public c(BoxView boxView) {
            this.boxView = boxView;
        }

        @Override // com.jcds.learneasy.widget.BoxView.b
        public void onClick(@NotNull Box box, boolean z) {
            ObservableListener aVar;
            Intrinsics.checkNotNullParameter(box, "box");
            List list = null;
            if (z) {
                ArrayList arrayList = ImageBoxView.this.mBoxList;
                if (arrayList == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    arrayList = null;
                }
                arrayList.add(box);
                ImageBoxView.this.f4418g++;
                List list2 = ImageBoxView.this.mBoxViews;
                if (list2 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                } else {
                    list = list2;
                }
                list.add(this.boxView);
                this.boxView.setNum(ImageBoxView.this.f4418g);
            } else {
                ImageBoxView imageBoxView = ImageBoxView.this;
                imageBoxView.f4418g--;
                ArrayList arrayList2 = ImageBoxView.this.mBoxList;
                if (arrayList2 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    arrayList2 = null;
                }
                arrayList2.remove(box);
                List list3 = ImageBoxView.this.mBoxViews;
                if (list3 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                } else {
                    list = list3;
                }
                list.remove(this.boxView);
                ImageBoxView.this.t(this.boxView);
            }
            if (ImageBoxView.this.mObservableListener != null && (aVar = ImageBoxView.this.mObservableListener) != null) {
                aVar.a(ImageBoxView.this.f4418g);
            }
        }
    }

    public final class d implements BoxView.OnViewEditClickListener {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ ImageBoxEntity f4427b;

        /* renamed from: c  reason: collision with root package name */
        public final /* synthetic */ BoxView f4428c;

        public d(ImageBoxEntity imageBoxEntity, BoxView boxView) {
            this.f4427b = imageBoxEntity;
            this.f4428c = boxView;
        }

        @Override // com.jcds.learneasy.widget.BoxView.c
        public void onEditClick() {
            OnBoxEditClickListener bVar = ImageBoxView.this.onBoxEditClickListener;
            if (bVar != null) {
                bVar.onEditClick(this.f4427b, this.f4428c);
            }
        }
    }

    public final class e implements BoxView.OnViewClickListener {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ BoxView f4430b;

        public e(BoxView boxView) {
            this.f4430b = boxView;
        }

        @Override // com.jcds.learneasy.widget.BoxView.b
        public void onClick(@NotNull Box box, boolean z) {
            ObservableListener aVar;
            Intrinsics.checkNotNullParameter(box, "box");
            int cuotiNo = box.getCuotiNo();
            List list = null;
            if (z) {
                ArrayList arrayList = ImageBoxView.this.mBoxList;
                if (arrayList == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    arrayList = null;
                }
                ArrayList arrayList2 = ImageBoxView.this.mAllBoxList;
                if (arrayList2 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                    arrayList2 = null;
                }
                ArrayList arrayList3 = new ArrayList();
                for (Object obj : arrayList2) {
                    if (((Box) obj).getCuotiNo() == cuotiNo) {
                        arrayList3.add(obj);
                    }
                }
                arrayList.addAll(arrayList3);
                ImageBoxView.this.f4418g++;
                List<BoxView> list2 = ImageBoxView.this.mAllBoxViews;
                if (list2 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
                    list2 = null;
                }
                ImageBoxView imageBoxView = ImageBoxView.this;
                ArrayList arrayList4 = new ArrayList();
                for (BoxView boxView : list2) {
                    if (boxView.getBox().getCuotiNo() == cuotiNo) {
                        boxView.setCheck(z);
                        boxView.setEdit(z);
                        boxView.j();
                        boxView.setNum(imageBoxView.f4418g);
                        List list3 = imageBoxView.mBoxViews;
                        if (list3 == null) {
                            Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                            list3 = null;
                        }
                        list3.add(boxView);
                    }
                    arrayList4.add(Unit.INSTANCE);
                }
            } else {
                ImageBoxView imageBoxView2 = ImageBoxView.this;
                imageBoxView2.f4418g--;
                List<BoxView> list4 = ImageBoxView.this.mAllBoxViews;
                if (list4 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
                    list4 = null;
                }
                ArrayList arrayList5 = new ArrayList();
                for (BoxView boxView2 : list4) {
                    if (boxView2.getBox().getCuotiNo() == cuotiNo) {
                        boxView2.setCheck(z);
                        boxView2.setEdit(z);
                        boxView2.j();
                    }
                    arrayList5.add(Unit.INSTANCE);
                }
                ArrayList arrayList6 = ImageBoxView.this.mBoxList;
                if (arrayList6 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    arrayList6 = null;
                }
                ArrayList arrayList7 = ImageBoxView.this.mAllBoxList;
                if (arrayList7 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                    arrayList7 = null;
                }
                ArrayList arrayList8 = new ArrayList();
                for (Object obj2 : arrayList7) {
                    if (((Box) obj2).getCuotiNo() == cuotiNo) {
                        arrayList8.add(obj2);
                    }
                }
                arrayList6.removeAll(arrayList8);
                List list5 = ImageBoxView.this.mBoxViews;
                if (list5 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                    list5 = null;
                }
                List list6 = ImageBoxView.this.mAllBoxViews;
                if (list6 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
                } else {
                    list = list6;
                }
                ArrayList arrayList9 = new ArrayList();
                for (Object obj3 : list) {
                    if (((BoxView) obj3).getBox().getCuotiNo() == cuotiNo) {
                        arrayList9.add(obj3);
                    }
                }
                list5.removeAll(arrayList9);
                ImageBoxView.this.t(this.f4430b);
            }
            if (!(ImageBoxView.this.mObservableListener == null || (aVar = ImageBoxView.this.mObservableListener) == null)) {
                aVar.a(ImageBoxView.this.f4418g);
            }
        }
    }

    public final class f implements BoxView.OnViewEditClickListener {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ ImageBoxEntity f4432b;

        /* renamed from: c  reason: collision with root package name */
        public final /* synthetic */ BoxView f4433c;

        public f(ImageBoxEntity imageBoxEntity, BoxView boxView) {
            this.f4432b = imageBoxEntity;
            this.f4433c = boxView;
        }

        @Override // com.jcds.learneasy.widget.BoxView.c
        public void onEditClick() {
            OnBoxEditClickListener bVar = ImageBoxView.this.onBoxEditClickListener;
            if (bVar != null) {
                bVar.onEditClick(this.f4432b, this.f4433c);
            }
        }
    }

    public final class g implements BoxView.OnMergeViewClickListener {

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ BoxView f4435b;

        public g(BoxView boxView) {
            this.f4435b = boxView;
        }

        @Override // com.jcds.learneasy.widget.BoxView.a
        public void onMergeClick(@NotNull Box box) {
            Object obj;
            ObservableListener aVar;
            boolean z;
            Intrinsics.checkNotNullParameter(box, "box");
            int cuotiNo = box.getCuotiNo();
            List list = ImageBoxView.this.mAllBoxViews;
            ArrayList arrayList = null;
            if (list == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
                list = null;
            }
            Iterator it = list.iterator();
            while (true) {
                if (!it.hasNext()) {
                    obj = null;
                    break;
                }
                obj = it.next();
                if (((BoxView) obj).getBox().getCuotiNo() == cuotiNo - 1) {
                    break;
                }
            }
            BoxView boxView = (BoxView) obj;
            if (boxView != null) {
                Box box2 = boxView.getBox();
                if (box2 != null) {
                    box2.setCuotiNo(cuotiNo);
                }
                if (boxView.f() && !this.f4435b.f()) {
                    int num = boxView.getNum();
                    this.f4435b.setCheck(true);
                    this.f4435b.j();
                    this.f4435b.setNum(num);
                    List list2 = ImageBoxView.this.mBoxViews;
                    if (list2 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                        list2 = null;
                    }
                    list2.add(this.f4435b);
                    ArrayList arrayList2 = ImageBoxView.this.mBoxList;
                    if (arrayList2 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    } else {
                        arrayList = arrayList2;
                    }
                    arrayList.add(this.f4435b.getBox());
                } else if (boxView.f() && this.f4435b.f()) {
                    ImageBoxView imageBoxView = ImageBoxView.this;
                    imageBoxView.f4418g--;
                    int num2 = this.f4435b.getNum();
                    int num3 = boxView.getNum();
                    if (num2 < num3) {
                        ImageBoxView.this.t(boxView);
                        boxView.setNum(num2);
                    } else {
                        ImageBoxView.this.t(this.f4435b);
                        this.f4435b.setNum(num3);
                    }
                } else if (boxView.f() || !this.f4435b.f()) {
                    ImageBoxView.this.f4418g++;
                    int i2 = ImageBoxView.this.f4418g;
                    this.f4435b.setCheck(true);
                    boxView.setCheck(true);
                    this.f4435b.setNum(i2);
                    boxView.setNum(i2);
                    this.f4435b.j();
                    boxView.j();
                    List list3 = ImageBoxView.this.mBoxViews;
                    if (list3 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                        list3 = null;
                    }
                    list3.add(this.f4435b);
                    List list4 = ImageBoxView.this.mBoxViews;
                    if (list4 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                        list4 = null;
                    }
                    list4.add(boxView);
                    ArrayList arrayList3 = ImageBoxView.this.mBoxList;
                    if (arrayList3 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                        arrayList3 = null;
                    }
                    arrayList3.add(this.f4435b.getBox());
                    ArrayList arrayList4 = ImageBoxView.this.mBoxList;
                    if (arrayList4 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    } else {
                        arrayList = arrayList4;
                    }
                    arrayList.add(boxView.getBox());
                } else {
                    int num4 = this.f4435b.getNum();
                    boxView.setCheck(true);
                    boxView.j();
                    boxView.setNum(num4);
                    List list5 = ImageBoxView.this.mBoxViews;
                    if (list5 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                        list5 = null;
                    }
                    list5.add(boxView);
                    ArrayList arrayList5 = ImageBoxView.this.mBoxList;
                    if (arrayList5 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                    } else {
                        arrayList = arrayList5;
                    }
                    arrayList.add(boxView.getBox());
                }
                this.f4435b.i();
                if (ImageBoxView.this.mObservableListener != null && (aVar = ImageBoxView.this.mObservableListener) != null) {
                    aVar.a(ImageBoxView.this.f4418g);
                }
            }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ImageBoxView(@NotNull Context context) {
        super(context);
        Intrinsics.checkNotNullParameter(context, "context");
    }

    public static final void q(ImageBoxView this$0, View view, int i2, int i3, int i4, int i5) {
        Intrinsics.checkNotNullParameter(this$0, "this$0");
        this$0.f4419h = i3;
        int childCount = ((LinearLayout) this$0.a(R.id.llContent)).getChildCount();
        int i6 = 0;
        int i7 = 0;
        i6 = 0;
        while (i6 < childCount) {
            i7 += ((LinearLayout) this$0.a(R.id.llContent)).getChildAt(i6).getHeight();
            if (i7 >= i3) {
                break;
            }
            i6++;
            i6 = i6;
        }
        ObservableListener aVar = this$0.mObservableListener;
        if (aVar != null) {
            aVar.b(i6, childCount);
        }
    }

    @Nullable
    public View a(int i2) {
        Map<Integer, View> map = this.f4423l;
        View view = map.get(Integer.valueOf(i2));
        if (view != null) {
            return view;
        }
        View findViewById = findViewById(i2);
        if (findViewById == null) {
            return null;
        }
        map.put(Integer.valueOf(i2), findViewById);
        return findViewById;
    }

    public final int getATempHeight() {
        return this.aTempHeight;
    }

    public final int getBoxCount() {
        return this.mBoxCount;
    }

    @NotNull
    public final ArrayList<Box> getImageBox() {
        ArrayList<Box> arrayList = this.mBoxList;
        if (arrayList != null) {
            return arrayList;
        }
        Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
        return null;
    }

    public final int getMScrollY() {
        return this.f4419h;
    }

    public final int getMWidth() {
        return this.f4412a;
    }

    public final void j(@NotNull Box box, @NotNull ImageBoxEntity mImageBoxEntity, int i2) {
        Intrinsics.checkNotNullParameter(box, "box");
        Intrinsics.checkNotNullParameter(mImageBoxEntity, "mImageBoxEntity");
        int width = mImageBoxEntity.getWidth();
        int height = mImageBoxEntity.getHeight();
        float x = box.getLeftTop().getX();
        int i3 = this.f4412a;
        float f2 = x * i3;
        int i4 = (int) ((i3 / width) * height);
        float x2 = (box.getRightTop().getX() - box.getLeftTop().getX()) * this.f4412a;
        float f3 = i4;
        float y = box.getLeftTop().getY() * f3;
        float y2 = (box.getLeftBottom().getY() - box.getLeftTop().getY()) * f3;
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams.leftMargin = (int) (f2 - 0.5f);
        int i5 = (int) (x2 + 0.5f);
        layoutParams.width = i5;
        layoutParams.topMargin = ((int) (y - 0.5f)) + i2;
        int i6 = (int) (y2 + 0.5f);
        layoutParams.height = i6;
        BoxView boxView = new BoxView(box, getContext(), i5, i6);
        boxView.setTempHeight(i2);
        ((RelativeLayout) a(R.id.rlParent)).addView(boxView);
        boxView.setLayoutParams(layoutParams);
        boxView.setBackgroundResource( R.drawable.bg_box_border);
        ArrayList<Box> arrayList = this.mBoxList;
        List<BoxView> list = null;
        if (arrayList == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
            arrayList = null;
        }
        arrayList.add(box);
        ArrayList<Box> arrayList2 = this.mAllBoxList;
        if (arrayList2 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
            arrayList2 = null;
        }
        arrayList2.add(box);
        List<BoxView> list2 = this.mBoxViews;
        if (list2 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
            list2 = null;
        }
        list2.add(boxView);
        List<BoxView> list3 = this.mAllBoxViews;
        if (list3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
        } else {
            list = list3;
        }
        list.add(boxView);
        boxView.setCheck(true);
        boxView.setEdit(true);
        boxView.j();
        int i7 = this.f4418g + 1;
        this.f4418g = i7;
        boxView.setNum(i7);
        boxView.setOnViewClickListener(new c(boxView));
        boxView.setOnViewEditClickListener(new d(mImageBoxEntity, boxView));
    }

    public final void k(ImageBoxEntity imageBoxEntity, Box box, int i2, int i3, Context context) {
        box.setBoxId(UUID.randomUUID().toString());
        this.mBoxCount = n() + 1;
        float x = box.getLeftTop().getX() * this.f4412a;
        float x2 = (box.getRightTop().getX() - box.getLeftTop().getX()) * this.f4412a;
        float f2 = i2;
        float y = box.getLeftTop().getY() * f2;
        float y2 = (box.getLeftBottom().getY() - box.getLeftTop().getY()) * f2;
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams.leftMargin = (int) (x - 0.5f);
        int i4 = (int) (x2 + 0.5f);
        layoutParams.width = i4;
        layoutParams.topMargin = ((int) (y - 0.5f)) + i3;
        int i5 = (int) (y2 + 0.5f);
        layoutParams.height = i5;
        BoxView boxView = new BoxView(box, context, i4, i5);
        boxView.setTempHeight(i3);
        List<BoxView> list = this.mAllBoxViews;
        if (list == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
            list = null;
        }
        list.add(boxView);
        ((RelativeLayout) a(R.id.rlParent)).addView(boxView);
        boxView.setLayoutParams(layoutParams);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            boxView.setBackgroundDrawable(context.getDrawable(R.drawable.bg_box_border));
        }
        boxView.setOnViewClickListener(new e(boxView));
        boxView.setOnViewEditClickListener(new f(imageBoxEntity, boxView));
        boxView.setOnMergeViewClickListener(new g(boxView));
    }

    public final void l(@NotNull ImageBoxEntity imageBoxEntity, @NotNull Context context) {
        Intrinsics.checkNotNullParameter(imageBoxEntity, "imageBoxEntity");
        Intrinsics.checkNotNullParameter(context, "context");
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        int width = imageBoxEntity.getWidth();
        int height = imageBoxEntity.getHeight();
        int i2 = this.f4412a;
        int i3 = (int) ((i2 / width) * height);
        layoutParams.height = i3;
        layoutParams.width = i2;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(layoutParams);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        ((LinearLayout) a(R.id.llContent)).addView(imageView);
//        d.e.a.b.t(context).q(imageBoxEntity.getDewarpImgUrl()).s0(imageView);
        Glide.with(context).load(imageBoxEntity.getDewarpImgUrl()).into(imageView);

        List<Box> boxList = imageBoxEntity.getBoxList();
        ArrayList<Box> arrayList = this.mAllBoxList;
        if (arrayList == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
            arrayList = null;
        }
        arrayList.addAll(boxList);
        int size = boxList.size();
        for (int i4 = 0; i4 < size; i4++) {
            k(imageBoxEntity, boxList.get(i4), i3, this.aTempHeight, context);
        }
        this.aTempHeight += i3;
    }

    public final void m(@NotNull List<ImageBoxEntity> imageBoxList, @NotNull Context context) {
        Intrinsics.checkNotNullParameter(imageBoxList, "imageBoxList");
        Intrinsics.checkNotNullParameter(context, "context");
        int size = imageBoxList.size();
        int i2 = 0;
        for (int i3 = 0; i3 < size; i3++) {
            ImageBoxEntity imageBoxEntity = imageBoxList.get(i3);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
            int width = imageBoxEntity.getWidth();
            int height = imageBoxEntity.getHeight();
            int i4 = this.f4412a;
            int i5 = (int) ((i4 / width) * height);
            layoutParams.height = i5;
            layoutParams.width = i4;
            ImageView imageView = new ImageView(context);
            imageView.setLayoutParams(layoutParams);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            ((LinearLayout) a(R.id.llContent)).addView(imageView);
            if (imageBoxEntity.getNeedDownload()) {
//                d.e.a.b.t(context).q(imageBoxEntity.getDewarpImgUrl()).s0(imageView);
                Glide.with(context).load(imageBoxEntity.getDewarpImgUrl()).into(imageView);
            } else {
//                d.e.a.b.t(context).q(imageBoxEntity.getFilePath()).s0(imageView);
                Glide.with(context).load(imageBoxEntity.getFilePath()).into(imageView);
            }
            List<Box> boxList = imageBoxEntity.getBoxList();
            ArrayList<Box> arrayList = this.mAllBoxList;
            if (arrayList == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList = null;
            }
            arrayList.addAll(boxList);
            int i6 = 0;
            for (int size2 = boxList.size(); i6 < size2; size2 = size2) {
                k(imageBoxEntity, boxList.get(i6), i5, i2, context);
                i6++;
            }
            i2 += i5;
        }
    }

    public final int n() {
        ArrayList<Box> arrayList = this.mAllBoxList;
        if (arrayList == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
            arrayList = null;
        }
        return arrayList.size();
    }

    public final void o(@NotNull BoxView boxView) {
        Object obj;
        Object obj2;
        Intrinsics.checkNotNullParameter(boxView, "boxView");
        ((RelativeLayout) a(R.id.rlParent)).removeView(boxView);
        List<BoxView> list = null;
        if (boxView.f()) {
            this.f4418g--;
            ArrayList<Box> arrayList = this.mBoxList;
            if (arrayList == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                arrayList = null;
            }
            ArrayList<Box> arrayList2 = this.mAllBoxList;
            if (arrayList2 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList2 = null;
            }
            Iterator<Box> it = arrayList2.iterator();
            while (true) {
                if (!it.hasNext()) {
                    obj2 = null;
                    break;
                }
                obj2 = it.next();
                if (Intrinsics.areEqual(((Box) obj2).getBoxId(), boxView.getBox().getBoxId())) {
                    break;
                }
            }
            TypeIntrinsics.asMutableCollection(arrayList).remove(obj2);
            List<BoxView> list2 = this.mBoxViews;
            if (list2 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                list2 = null;
            }
            list2.remove(boxView);
            t(boxView);
        }
        ArrayList<Box> arrayList3 = this.mAllBoxList;
        if (arrayList3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
            arrayList3 = null;
        }
        ArrayList<Box> arrayList4 = this.mAllBoxList;
        if (arrayList4 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
            arrayList4 = null;
        }
        Iterator<Box> it2 = arrayList4.iterator();
        while (true) {
            if (!it2.hasNext()) {
                obj = null;
                break;
            }
            obj = it2.next();
            if (Intrinsics.areEqual(((Box) obj).getBoxId(), boxView.getBox().getBoxId())) {
                break;
            }
        }
        TypeIntrinsics.asMutableCollection(arrayList3).remove(obj);
        List<BoxView> list3 = this.mAllBoxViews;
        if (list3 == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
        } else {
            list = list3;
        }
        list.remove(boxView);
    }

    @Override // android.widget.FrameLayout, android.view.View
    public void onMeasure(int i2, int i3) {
        super.onMeasure(i2, i3);
        this.f4412a = View.MeasureSpec.getSize(i2);
    }

    public final void p(@NotNull Context context, @NotNull AttributeSet attrs) {
        Intrinsics.checkNotNullParameter(context, "context");
        Intrinsics.checkNotNullParameter(attrs, "attrs");
        View.inflate(context, R.layout.layout_image_box, this);
        this.mAllBoxList = new ArrayList<>();
        this.mAllBoxViews = new ArrayList();
        this.mBoxList = new ArrayList<>();
        this.mBoxViews = new ArrayList();
        if (Build.VERSION.SDK_INT >= 23) {
            ((ScrollView) a(R.id.scrollview)).setOnScrollChangeListener(new View.OnScrollChangeListener() { // from class: d.m.b.n.d
                @Override // android.view.View.OnScrollChangeListener
                public final void onScrollChange(View view, int i2, int i3, int i4, int i5) {
                    ImageBoxView.q(ImageBoxView.this, view, i2, i3, i4, i5);
                }
            });
        }
    }

    public final void s(@NotNull BoxView boxView, @NotNull ImageBoxEntity mImageBoxEntity) {
        Object obj;
        Object obj2;
//        Intrinsics.checkNotNullParameter(boxView, "boxView");
//        Intrinsics.checkNotNullParameter(mImageBoxEntity, "mImageBoxEntity");
        ArrayList<Box> arrayList = null;
        if (boxView.f()) {
            ArrayList<Box> arrayList2 = this.mAllBoxList;
            if (arrayList2 == null) {
//                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList2 = null;
            }
            Iterator<Box> it = arrayList2.iterator();
            while (true) {
                if (!it.hasNext()) {
                    obj2 = null;
                    break;
                }
                obj2 = it.next();
                if (Intrinsics.areEqual(((Box) obj2).getBoxId(), boxView.getBox().getBoxId())) {
                    break;
                }
            }
            Box box = (Box) obj2;
            ArrayList<Box> arrayList3 = this.mBoxList;
            if (arrayList3 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                arrayList3 = null;
            }
//            int indexOf = CollectionsKt___CollectionsKt.indexOf((List<? extends Box>) arrayList3, box);
            int indexOf = arrayList3.indexOf(box);
            ArrayList<Box> arrayList4 = this.mAllBoxList;
            if (arrayList4 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList4 = null;
            }
//            int indexOf2 = CollectionsKt___CollectionsKt.indexOf((List<? extends Box>) arrayList4, box);
            int indexOf2 = arrayList4.indexOf(box);
            ArrayList<Box> arrayList5 = this.mAllBoxList;
            if (arrayList5 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList5 = null;
            }
            arrayList5.set(indexOf2, boxView.getBox());
            ArrayList<Box> arrayList6 = this.mBoxList;
            if (arrayList6 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
            } else {
                arrayList = arrayList6;
            }
            arrayList.set(indexOf, boxView.getBox());
        } else {
            boxView.setCheck(true);
            boxView.setEdit(true);
            boxView.j();
            ArrayList<Box> arrayList7 = this.mAllBoxList;
            if (arrayList7 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList7 = null;
            }
            Iterator<Box> it2 = arrayList7.iterator();
            while (true) {
                if (!it2.hasNext()) {
                    obj = null;
                    break;
                }
                obj = it2.next();
                if (Intrinsics.areEqual(((Box) obj).getBoxId(), boxView.getBox().getBoxId())) {
                    break;
                }
            }
            Box box2 = (Box) obj;
            ArrayList<Box> arrayList8 = this.mAllBoxList;
            if (arrayList8 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList8 = null;
            }
//            int indexOf3 = CollectionsKt___CollectionsKt.indexOf((List<? extends Box>) arrayList8, box2);
            int indexOf3 = arrayList8.indexOf(box2);
            ArrayList<Box> arrayList9 = this.mAllBoxList;
            if (arrayList9 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList9 = null;
            }
            arrayList9.set(indexOf3, boxView.getBox());
            int cuotiNo = boxView.getBox().getCuotiNo();
            ArrayList<Box> arrayList10 = this.mBoxList;
            if (arrayList10 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxList");
                arrayList10 = null;
            }
            ArrayList<Box> arrayList11 = this.mAllBoxList;
            if (arrayList11 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxList");
                arrayList11 = null;
            }
            ArrayList arrayList12 = new ArrayList();
            for (Object obj3 : arrayList11) {
                if (((Box) obj3).getCuotiNo() == cuotiNo) {
                    arrayList12.add(obj3);
                }
            }
            arrayList10.addAll(arrayList12);
            this.f4418g++;
            List<BoxView> list = this.mAllBoxViews;
            if (list == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mAllBoxViews");
                list = null;
            }
            ArrayList arrayList13 = new ArrayList();
            for (BoxView boxView2 : list) {
                if (boxView2.getBox().getCuotiNo() == boxView.getBox().getCuotiNo()) {
                    boxView.setNum(this.f4418g);
                    List<BoxView> list2 = this.mBoxViews;
                    if (list2 == null) {
                        Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                        list2 = null;
                    }
                    list2.add(boxView2);
                }
                arrayList13.add(Unit.INSTANCE);
            }
        }
        int width = mImageBoxEntity.getWidth();
        int height = mImageBoxEntity.getHeight();
        Box box3 = boxView.getBox();
        float x = box3.getLeftTop().getX();
        int i2 = this.f4412a;
        float f2 = x * i2;
        int i3 = (int) ((i2 / width) * height);
        float x2 = (box3.getRightTop().getX() - box3.getLeftTop().getX()) * this.f4412a;
        float f3 = i3;
        float y = box3.getLeftTop().getY() * f3;
        float y2 = (box3.getLeftBottom().getY() - box3.getLeftTop().getY()) * f3;
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-2, -2);
        layoutParams.leftMargin = (int) (f2 - 0.5f);
        layoutParams.width = (int) (x2 + 0.5f);
        layoutParams.topMargin = ((int) (y - 0.5f)) + boxView.getTempHeight();
        layoutParams.height = (int) (y2 + 0.5f);
        boxView.setLayoutParams(layoutParams);
    }

    public final void setATempHeight(int i2) {
        this.aTempHeight = i2;
    }

    public final void setBoxCount(int i2) {
        this.mBoxCount = i2;
    }

    public final void setMScrollY(int i2) {
        this.f4419h = i2;
    }

    public final void setMWidth(int i2) {
        this.f4412a = i2;
    }

    public final void setObservableListener(@NotNull ObservableListener observableListener) {
        Intrinsics.checkNotNullParameter(observableListener, "observableListener");
        this.mObservableListener = observableListener;
    }

    public final void setOnEditClickListener(@NotNull OnBoxEditClickListener onBoxEditClickListener) {
        Intrinsics.checkNotNullParameter(onBoxEditClickListener, "onBoxEditClickListener");
        this.onBoxEditClickListener = onBoxEditClickListener;
    }

    public final void setTipsState(boolean z) {
        if (z) {
//            d.e.a.b.t(getContext()).q("file:///android_asset/app-loading.gif").g(h.f13069c).s0((ImageView) a(R.id.ivLoading));
            ((RelativeLayout) a(R.id.rlLoading)).setVisibility(View.VISIBLE);
            return;
        }
        ((RelativeLayout) a(R.id.rlLoading)).setVisibility(View.GONE);
    }

    public final void t(@NotNull BoxView view) {
        Intrinsics.checkNotNullParameter(view, "view");
        int num = view.getNum();
        List<BoxView> list = this.mBoxViews;
        if (list == null) {
            Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
            list = null;
        }
        int size = list.size();
        for (int i2 = 0; i2 < size; i2++) {
            List<BoxView> list2 = this.mBoxViews;
            if (list2 == null) {
                Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                list2 = null;
            }
            int num2 = list2.get(i2).getNum();
            if (num < num2) {
                List<BoxView> list3 = this.mBoxViews;
                if (list3 == null) {
                    Intrinsics.throwUninitializedPropertyAccessException("mBoxViews");
                    list3 = null;
                }
                list3.get(i2).setNum(num2 - 1);
            }
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ImageBoxView(@NotNull Context context, @NotNull AttributeSet attrs) {
        super(context, attrs);
//        Intrinsics.checkNotNullParameter(context, "context");
//        Intrinsics.checkNotNullParameter(attrs, "attrs");
        p(context, attrs);
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ImageBoxView(@NotNull Context context, @NotNull AttributeSet attrs, int i2) {
        super(context, attrs, i2);
//        Intrinsics.checkNotNullParameter(context, "context");
//        Intrinsics.checkNotNullParameter(attrs, "attrs");
        p(context, attrs);
    }
}